package com.dxtan90.utils;

import com.dxtan90.bean.Position;

import java.awt.event.KeyEvent;
import java.lang.reflect.Field;

/**
 * @author: shijunhao
 * @date: 2021/12/2 16:16
 * @description:
 */
public class PositionUtils {

    public static Position parseXYPosition(String order){
        String[] split = order.split(",");
        Integer x = Integer.valueOf(split[0]);
        Integer y = Integer.valueOf(split[1]);
        Position position = new Position();
        position.setCenterX(x);
        position.setCenterY(y);
        position.setUseful(true);
        return position;
    }

    public static Position parseKeyPosition(String order){
        Class keyEvent = KeyEvent.class;
        Field[] declaredFields = keyEvent.getDeclaredFields();
        for(Field field:declaredFields){
            field.setAccessible(true);
            if(field.getName().equals(order)){
                try {
                    return new Position(field.getInt(null));
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }

}
